
package DBM;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;

public class BuildDB {
	Connection	con	= null;

	public BuildDB( DBManager DBM ) {
		this.con = DBM.getConnection();
	}

	public void buildDB() {
		try {
			Statement stmt = con.createStatement();
			stmt.execute( "CREATE TABLE Account (" + "accountID INT NOT NULL,"
					+ "characterID INT NOT NULL,"
					+ "realName VARCHAR(40) NOT NULL,"
					+ "password VARCHAR(40) NOT NULL,"
					+ "email VARCHAR(80) NOT NULL)" );
			System.out.println( "Table Account created" );
			stmt.execute( "CREATE TABLE CharacterO ("
					+ "characterID INT NOT NULL," + "health INT,"
					+ "charName VARCHAR(40) NOT NULL," + "experience INT,"
					+ "level INT," + "moneyCash BIGINT," + "moneyBank BIGINT,"
					+ "equipmentID INT," + "shootExperience INT,"
					+ "respect INT," + "networkID INT,"
					+ "landID INT, objectID INT, vip BOOLEAN,"
					+ "administrator BOOLEAN, homeID INT, " 
					+ " mailID INT, backfire INT)" );
			System.out.println( "Table Character created" );
			stmt.execute( "CREATE TABLE Action (" + "accountID INT NOT NULL,"
					+ "characterID INT NOT NULL,"
					+ "Jail VARCHAR(40) NOT NULL,"
					+ "simpleCrime VARCHAR(40) NOT NULL,"
					+ "bigCrime VARCHAR(40) NOT NULL,"
					+ "shootArea VARCHAR(40) NOT NULL)" );
			System.out.println( "Table Action created" );
			stmt.execute( "CREATE TABLE Mail ("
					+ "mailID INT NOT NULL AUTO_INCREMENT,"
					+ "mailFromID INT NOT NULL," + "mailToID INT NOT NULL,"
					+ "title VARCHAR(40) NOT NULL,"
					+ "content VARCHAR(1220) NOT NULL, "
					+ "dateTime VARCHAR(40) NOT NULL,"
					+ "isRead BOOLEAN NOT NULL, " + "PRIMARY KEY (mailID))" );
			System.out.println( "Table Mail created" );
			stmt.execute( "CREATE TABLE Log ("
					+ "logID INT NOT NULL AUTO_INCREMENT,"
					+ "accountID INT NOT NULL," + "accepted BOOLEAN NOT NULL,"
					+ "ip VARCHAR(40) NOT NULL,"
					+ "time VARCHAR(40) NOT NULL, "
					+ "userAgent VARCHAR(255) NOT NULL,"
					+ "PRIMARY KEY (logID))" );
			System.out.println( "Table Log created" );
			stmt.execute( "CREATE TABLE Support ("
					+ "supportID INT NOT NULL AUTO_INCREMENT,"
					+ "accountID INT NOT NULL,"
					+ "subject VARCHAR(40) NOT NULL,"
					+ "email VARCHAR(40) NOT NULL, "
					+ "content VARCHAR(1220) NOT NULL,"
					+ "dateTime VARCHAR(40) NOT NULL,"
					+ "isRead BOOLEAN NOT NULL," + "PRIMARY KEY (supportID))" );
			System.out.println( "Table Support created" );
			stmt.execute( "CREATE TABLE Equipment ("
					+ "equipmentID INT NOT NULL," + "sniper BOOLEAN NOT NULL,"
					+ "bomb BOOLEAN NOT NULL," + "uziSMG BOOLEAN NOT NULL,"
					+ "desertEagle BOOLEAN NOT NULL,"
					+ "barakSP21 BOOLEAN NOT NULL,"
					+ "coltM1911 BOOLEAN NOT NULL," + "knife BOOLEAN NOT NULL,"
					+ "bulletFreeArmor BOOLEAN NOT NULL,"
					+ "bulletFreeHelmet BOOLEAN NOT NULL,"
					+ "bombArmor BOOLEAN NOT NULL," + "bodyguard INT NOT NULL,"
					+ "bullet INT NOT NULL )" );
			System.out.println( "Table Equipment created" );
		} catch( SQLException e ) {
			System.err.println( "SQL error in build Database" );
			e.printStackTrace();
		}
	}

	public void dropDB() {
		try {
			Statement stmt = con.createStatement();
			stmt.execute( "DROP TABLE Account" );
			stmt.execute( "DROP TABLE CharacterO" );
			stmt.execute( "DROP TABLE Action" );
			stmt.execute( "DROP TABLE Log" );
			stmt.execute( "DROP TABLE Mail" );
			stmt.execute( "DROP TABLE Support" );
			stmt.execute( "DROP TABLE Equipment" );
		} catch( SQLException e ) {
			System.err.println( "SQL error drop Database" );
		}
	}
}
